﻿using CIS.DB;
using CIS.Web.Common;
using CIS.Web.Models;
using CIS.Web.Properties;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Linq.Dynamic;
using System.Threading.Tasks;
using System.Web.Mvc;
using static System.Net.Mime.MediaTypeNames;

namespace CIS.Web.Controllers
{
	[RoutePrefix("SysUserMaster")]
	public class SysUserMasterController : BaseDbController
	{
		private string _importMessage;

		public ActionResult Index()
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			return View();
		}

		public async Task<JsonCamelCaseResult> GetData(int? page, int? rows, string sort, string order, SysUserMasterModel model)
		{
			int take = rows ?? ConstValues.DefaultGridRows;
			int skip = ((page ?? 1) - 1) * take;

			var sql = from userInfo in DbContext.SysUserMaster.AsNoTracking().Where(x => !string.IsNullOrEmpty(x.Status))
				  join countryInfo in DbContext.LocationMaster.AsNoTracking().Where(x => x.Level == ConstValues.LocationLevel.国家)
					on userInfo.Country equals countryInfo.ID into countrys
				  from country in countrys.DefaultIfEmpty()
				  select new
				  {
					  ID = userInfo.ID,
					  UserName = userInfo.UserName,
					  FamilyName = userInfo.FamilyName,
					  FirstName = userInfo.FirstName,
					  FullName = userInfo.FullName,
					  Gender = userInfo.Gender,
					  Mail = userInfo.Mail,
					  Birthday = userInfo.Birthday,
					  Affiliation = userInfo.Affiliation,
					  Call = userInfo.Call,
					  Degree = userInfo.Degree,
					  Career = userInfo.Career,
					  Telephone = userInfo.Telephone,
					  Mobile = userInfo.Mobile,
					  Country = country.Name,
					  CountryEn = country.NameEn,
					  State = userInfo.StateStr,
					  City = userInfo.CityStr,
					  Address = userInfo.Address,
					  ZipCode = userInfo.ZipCode,
					  OcisCode = userInfo.OcisCode,
					  Department = userInfo.Department,
					  InvoiceTitle = userInfo.InvoiceTitle,
					  TaxNum = userInfo.TaxNum,
					  AddressAndTel = userInfo.AddressAndTel,
					  Bank = userInfo.Bank,
					  BankAccount = userInfo.BankAccount,
					  LockTime = userInfo.LockTime,
					  PasswordFailed = userInfo.PasswordFailed,
					  IsLocked = userInfo.IsLocked,
					  Status = userInfo.Status,
					  Sort = userInfo.Sort,
					  Remark = userInfo.Remark,
					  Creator = userInfo.Creator,
					  CreateIP = userInfo.CreateIP,
					  CreateDate = userInfo.CreateDate,
					  UpdateDate = userInfo.UpdateDate,
				  };

			//用户名，姓名，邮箱 模糊查询
			if (!string.IsNullOrWhiteSpace(model.SelUserName))
			{
				sql = sql.Where(x => x.FullName.Contains(model.SelUserName) ||
					(x.FirstName.Contains(model.SelUserName) &&
					x.FamilyName.Contains(model.SelUserName)) ||
					x.UserName.Contains(model.SelUserName) ||
					x.Mail.Contains(model.SelUserName));
			}

			if (!string.IsNullOrWhiteSpace(model.SelStatus))
			{
				sql = sql.Where(x => x.Status == model.SelStatus);
			}

			if (model.SelLock == ConstValues.IsLock.否)
			{
				sql = sql.Where(x => !x.IsLocked);
			}
			else if (model.SelLock == ConstValues.IsLock.是)
			{
				sql = sql.Where(x => x.IsLocked);
			}

			int total = await sql.CountAsync();

			if (!string.IsNullOrEmpty(sort))
			{
				sql = sql.OrderBy(sort + ConstValues.chrSpace + order).Skip(skip).Take(take);
			}
			else
			{
				sql = sql.OrderBy(x => x.Sort).OrderByDescending(x => x.CreateDate).Skip(skip).Take(take);
			}

			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				ID = x.ID,
				UserName = x.UserName,
				FamilyName = x.FamilyName,
				FirstName = x.FirstName,
				FullName = x.FullName == null ? string.Empty : x.FullName,
				Gender = x.Gender ? Resources.Male : Resources.Female,
				Mail = x.Mail,
				Birthday = x.Birthday == null ? string.Empty : (LoginUser.Language == ConstValues.Language.Cn ? x.Birthday.Value.ToString("yyyy-MM-dd") : x.Birthday.Value.ToString("MM/dd/yyyy")),
				Affiliation = x.Affiliation,
				Title = LoginUser.Language == ConstValues.Language.Cn ?
						DbContext.CallMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.Call)?.CallName :
						DbContext.CallMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.Call)?.CallNameEn,
				Degree = LoginUser.Language == ConstValues.Language.Cn ?
						DbContext.DegreeMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.Degree)?.DegreeName :
						DbContext.DegreeMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.Degree)?.DegreeNameEn,
				Career = Utility.GetNameFromIdList(x.Career, "career", LoginUser.Language),
				Careerlist = x.Career?.Split(ConstValues.chrSemicolon),
				Telephone = x.Telephone,
				Mobile = x.Mobile,
				City = x.City,
				State = x.State,
				Country = LoginUser.Language == ConstValues.Language.Cn ? x.Country : x.CountryEn,
				Address = x.Address,
				ZipCode = x.ZipCode,
				OcisCode = Utility.GetNameFromIdList(x.OcisCode, "ocis"),
				OcisCodelist = x.OcisCode.Split(ConstValues.chrSemicolon),
				Department = x.Department,
				InvoiceTitle = x.InvoiceTitle,
				TaxNum = x.TaxNum,
				AddressAndTel = x.AddressAndTel,
				Bank = x.Bank,
				BankAccount = x.BankAccount,
				LockTime = x.LockTime,
				IsLocked = x.IsLocked ? Resources.Yes : Resources.No,
				PasswordFailed = x.PasswordFailed,
				Status = x.Status,
				Sort = x.Sort,
				Remark = x.Remark,
				Creator = x.Creator,
				CreateIP = x.CreateIP,
				CreateDate = LoginUser.Language == ConstValues.Language.Cn ?
							x.CreateDate.Value.ToString("yyyy-MM-dd") :
							x.CreateDate.Value.ToString("MM/dd/yyyy")
			});

			return JsonCamelCase(new
			{
				Total = total,
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetEditData(string id)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			var sysUserMaster = await DbContext.SysUserMaster.AsNoTracking().FirstOrDefaultAsync(x => x.ID == id);

			if (sysUserMaster != null)
			{
				var sysUserMasterEn = await DbContext.SysUserMasterEn.AsNoTracking().FirstOrDefaultAsync(x => x.UserName == sysUserMaster.UserName);
				var result = new
				{
					IsLocked = sysUserMaster.IsLocked ? ConstValues.IsLock.是 : ConstValues.IsLock.否,
					Status = sysUserMaster.Status,
					Sort = sysUserMaster.Sort,
					Remark = sysUserMaster.Remark,

					UserName = sysUserMaster.UserName,
					Mail = sysUserMaster.Mail,
					Language = sysUserMaster.Language,
					FullName = sysUserMaster.FullName,
					FullNameEN = sysUserMasterEn?.FullName,
					FamilyName = sysUserMaster.FamilyName,
					FamilyNameEN = sysUserMasterEn?.FamilyName,
					FirstName = sysUserMaster.FirstName,
					FirstNameEN = sysUserMasterEn?.FirstName,
					Gender = sysUserMaster.Gender,
					Birthday = Utility.SetDate(sysUserMaster.Birthday, Request.Cookies["_culture"].Value),
					Call =sysUserMaster.Call,
					CallEN = sysUserMasterEn?.Call,
					Degree = DbContext.DegreeMaster.AsNoTracking().FirstOrDefault(x => x.ID == sysUserMaster.Degree)?.ID,
					Career = sysUserMaster.Career?.Split(ConstValues.chrSemicolon),
					OcisCode = sysUserMaster.OcisCode?.Split(ConstValues.chrSemicolon),
					CV = sysUserMaster.CV,
					CVEN = sysUserMasterEn?.CV,
					Affiliation = sysUserMaster.Affiliation,
					AffiliationEN = sysUserMasterEn?.Affiliation,
					Department = sysUserMaster.Department,
					DepartmentEN = sysUserMasterEn?.Department,
					Address = sysUserMaster.Address,
					AddressEN = sysUserMasterEn?.Address,
					ZipCode = sysUserMaster.ZipCode,
					Country = DbContext.LocationMaster.AsNoTracking().FirstOrDefault(x => x.ID == sysUserMaster.Country)?.ID,
					State = sysUserMaster.StateStr,
					City = sysUserMaster.CityStr,
					Mobile = sysUserMaster.Mobile,
					Telephone = sysUserMaster.Telephone,

					InvoiceTitle = sysUserMaster.InvoiceTitle,
					TaxNum = sysUserMaster.TaxNum,
					AddressAndTel = sysUserMaster.AddressAndTel,
					Bank = sysUserMaster.Bank,
					BankAccount = sysUserMaster.BankAccount,
				};

				return JsonCamelCase(Utility.CreateSuccessJsonResult(string.Empty, result),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> DeleteUser(SysUserMasterModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			var sysUserMaster = await DbContext.SysUserMaster
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (sysUserMaster != null)
			{
				DbContext.SysUserMaster.Remove(sysUserMaster);

				var sysUserEnMaster = await DbContext.SysUserMasterEn
						.FirstOrDefaultAsync(y => y.Mail == sysUserMaster.Mail);
				if (sysUserEnMaster != null)
				{
					DbContext.SysUserMasterEn.Remove(sysUserEnMaster);
				}

				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> Create(SysUserMasterModel model, FormCollection formCollection)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			var result = await DbContext.SysUserMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.UserName == model.UserName || x.Mail == model.Mail);
			if (result != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
						string.Format(Resources.MsgRecordExist, Resources.UserName)),
						JsonRequestBehavior.AllowGet);
			}

			//if (model.HeadImgFile != null)
			//{
			//	if (model.HeadImgFile.ContentLength > ConstValues.PicMaxLength)
			//	{
			//		string errorMessage = Resources.MsgPicOverflowError;
			//		return JsonCamelCase(Utility.CreateFailJsonResult(errorMessage),
			//			JsonRequestBehavior.AllowGet);
			//	}

			//	string folder = ConstValues.UserHeadImg;
			//	string pfolder = Server.MapPath(ConstValues.UserHeadImg);
			//	string fileName = ConstValues.TableId.SysUserMaster + ConstValues.strHyphen +
			//			DateTime.Now.ToString("yyyyMMdd") + ConstValues.strHyphen +
			//			Utility.GetRandom() + Path.GetExtension(model.HeadImgFile.FileName);
			//	model.HeadImgFilePath = Path.Combine(folder, fileName);
			//	var saveFileTask = Task.Run(() =>
			//	{
			//		string pFullPath = Path.Combine(pfolder, fileName);
			//		if (!Directory.Exists(pfolder))
			//		{
			//			Directory.CreateDirectory(pfolder);
			//		}
			//		model.HeadImgFile.SaveAs(pFullPath);
			//	});
			//	Task.WaitAll(saveFileTask);
			//}

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				var career = string.Join(ConstValues.strSemicolon, model.Career);
				var ocisCode = string.Join(ConstValues.strSemicolon, model.OcisCode);

				result = new SysUserMaster
				{
					ID = Utility.GetTableId(ConstValues.TableName.SysUserMaster),
					IsLocked = model.Lock == ConstValues.IsLock.否 ? false : true,
					Status = model.Status,
					Sort = model.Sort.HasValue ? model.Sort.Value : ConstValues.DefaultSort,
					Remark = model.Remark?.Trim(),

					UserName = model.UserName?.Trim(),
					Mail = model.Mail?.Trim(),
					Language = model.Language,
					FullName = !string.IsNullOrEmpty(model.FullName) ? model.FullName?.Trim() :
						Utility.SetFullName(model.FamilyName?.Trim(), model.FirstName?.Trim(), model.Language),
					FamilyName = model.FamilyName?.Trim(),
					FirstName = model.FirstName?.Trim(),
					Gender = model.GenderStr == ConstValues.Gender.女 ? false : true,
					Birthday = model.Birthday,
					Call = model.Call,
					Degree = model.Degree,
					Career = string.Join(ConstValues.strSemicolon, model.Career),
					OcisCode = string.Join(ConstValues.strSemicolon, model.OcisCode),
					CV = model.CV?.Trim(),
					Affiliation = model.Affiliation?.Trim(),
					Department = model.Department?.Trim(),
					Address = model.Address?.Trim(),
					ZipCode = model.ZipCode?.Trim(),
					Country = model.Country,
					StateStr = model.State,
					CityStr = model.City,
					Telephone = model.Telephone?.Trim(),
					Mobile = model.Mobile?.Trim(),

					InvoiceTitle = model.InvoiceTitle,
					TaxNum = model.TaxNum,
					AddressAndTel = model.AddressAndTel,
					Bank = model.Bank,
					BankAccount = model.BankAccount,

					Password = StringExtension.Encrypt(ConstValues.DefaultPassword),
					PasswordFailed = ConstValues.intZero,
					Creator = LoginUser.UserName,
					CreateIP = LoginUser.IP,
					CreateDate = DateTime.Now,
					HasSend = false,
					HasUpdate = true,

					//NickName = model.NickName?.Trim(),
					//Rank = model.Rank?.Trim(),
					//Type = model.Type?.Trim(),
					//Organization = model.Organization?.Trim(),
					//Blog = model.Blog?.Trim(),
					//Sign = model.Sign?.Trim(),
					//Point = model.Point?.Trim(),
					//Question = model.Question?.Trim(),
					//Answer = model.Answer?.Trim(),
					//Others = model.Others?.Trim(),
				};

				DbContext.SysUserMaster.Add(result);

				if (model.Language == ConstValues.Language.Cn)
				{
					var sysUserMasterEn = new SysUserMasterEn
					{
						ID = Utility.GetTableId(ConstValues.TableName.SysUserMasterEn),
						FullName = !string.IsNullOrEmpty(model.FullNameEN) ? model.FullNameEN?.Trim() :
							Utility.SetFullName(model.FamilyNameEN?.Trim(), model.FirstNameEN?.Trim(), ConstValues.Language.En),
						FamilyName = model.FamilyNameEN?.Trim(),
						FirstName = model.FirstNameEN?.Trim(),
						Call = model.CallEN,
						Address = model.AddressEN?.Trim(),
						Affiliation = model.AffiliationEN?.Trim(),
						Department = model.DepartmentEN?.Trim(),
						CV = model.CVEN?.Trim(),
						
						UserName = result.UserName,
						Mail = result.Mail,
						Gender = result.Gender,
						Degree = result.Degree,
						Country = result.Country,
						StateStr = result.StateStr,
						CityStr = result.CityStr,
						Telephone = result.Telephone,
						Mobile = result.Mobile,
						Career = career,
						OcisCode = ocisCode,
						HasUpdate = true,
						Status = ConstValues.Status.正常,
						Sort = ConstValues.DefaultSort,
						Creator = LoginUser.UserName,
						CreateIP = LoginUser.IP,
						CreateDate = DateTime.Now,
					};
					DbContext.SysUserMasterEn.Add(sysUserMasterEn);
				}

				Utility.SaveInvoiceInfo(LoginUser, new InvoiceModel
				{
					InvoiceTitle = model.InvoiceTitle,
					TaxNum = model.TaxNum,
					AddressAndTel = model.AddressAndTel,
					Bank = model.Bank,
					BankAccount = model.BankAccount,
				});

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> Modify(SysUserMasterModel model, FormCollection formCollection)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			var result = await DbContext.SysUserMaster.FirstOrDefaultAsync(x => x.ID == model.Id);
			if (result == null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
					JsonRequestBehavior.AllowGet);
			}

			//if (model.HeadImgFile != null)
			//{
			//	if (model.HeadImgFile.ContentLength > ConstValues.PicMaxLength)
			//	{
			//		string errorMessage = Resources.MsgPicOverflowError;
			//		return JsonCamelCase(Utility.CreateFailJsonResult(errorMessage),
			//			JsonRequestBehavior.AllowGet);
			//	}

			//	string folder = ConstValues.UserHeadImg;
			//	string pfolder = Server.MapPath(ConstValues.UserHeadImg);
			//	string fileName = ConstValues.TableId.SysUserMaster + ConstValues.strHyphen +
			//			DateTime.Now.ToString("yyyyMMdd") + ConstValues.strHyphen +
			//			Utility.GetRandom() + Path.GetExtension(model.HeadImgFile.FileName);
			//	model.HeadImgFilePath = Path.Combine(folder, fileName);
			//	var saveFileTask = Task.Run(() =>
			//	{
			//		string pFullPath = Path.Combine(pfolder, fileName);
			//		if (!Directory.Exists(pfolder))
			//		{
			//			Directory.CreateDirectory(pfolder);
			//		}
			//		model.HeadImgFile.SaveAs(pFullPath);
			//	});
			//	Task.WaitAll(saveFileTask);
			//	result.HeadImg = model.HeadImgFilePath;
			//}
				
			using (var transaction = DbContext.Database.BeginTransaction())
			{
				var career = string.Join(ConstValues.strSemicolon, model.Career);
				var ocisCode = string.Join(ConstValues.strSemicolon, model.OcisCode);

				result.IsLocked = model.Lock == ConstValues.IsLock.否 ? false : true;
				result.Status = model.Status;
				result.Sort = model.Sort.HasValue ? model.Sort.Value : ConstValues.DefaultSort;
				result.Remark = model.Remark?.Trim();

				result.Language = model.Language;
				result.FullName = !string.IsNullOrEmpty(model.FullName) ? model.FullName?.Trim() :
						Utility.SetFullName(model.FamilyName?.Trim(), model.FirstName?.Trim(), model.Language);
				result.FamilyName = model.FamilyName?.Trim();
				result.FirstName = model.FirstName?.Trim();
				result.Gender = model.GenderStr == ConstValues.Gender.女 ? false : true;
				result.Birthday = model.Birthday;
				result.Call = model.Call;
				result.Degree = model.Degree;
				result.Career = career;
				result.OcisCode = ocisCode;
				result.CV = model.CV?.Trim();
				result.Affiliation = model.Affiliation?.Trim();
				result.Department = model.Department?.Trim();
				result.Address = model.Address?.Trim();
				result.ZipCode = model.ZipCode?.Trim();
				result.Country = model.Country;
				result.StateStr = model.State;
				result.CityStr = model.City;
				result.Telephone = model.Telephone?.Trim();
				result.Mobile = model.Mobile?.Trim();

				//result.NickName = model.NickName?.Trim();
				//result.Rank = model.Rank?.Trim();
				//result.Type = model.Type?.Trim();
				//result.Organization = model.Organization?.Trim();
				//result.Blog = model.Blog?.Trim();
				//result.Sign = model.Sign?.Trim();
				//result.Point = model.Point?.Trim();
				//result.Question = model.Question?.Trim();
				//result.Answer = model.Answer?.Trim();
				//result.Others = model.Others?.Trim();

				if (!string.IsNullOrWhiteSpace(model.InvoiceTitle))
				{
					result.InvoiceTitle = model.InvoiceTitle;
					result.TaxNum = model.TaxNum;
					result.AddressAndTel = model.AddressAndTel;
					result.Bank = model.Bank;
					result.BankAccount = model.BankAccount;
				}

				result.HasUpdate = true;
				result.PasswordFailed = ConstValues.intZero;
				result.Updater = LoginUser.UserName;
				result.UpdateDate = DateTime.Now;
				result.UpdateIP = LoginUser.IP;

				if (model.Language == ConstValues.Language.Cn)
				{
					var sysUserMasterEn = await DbContext.SysUserMasterEn.FirstOrDefaultAsync(x => x.UserName == result.UserName);
					if (sysUserMasterEn == null)
					{
						sysUserMasterEn = new SysUserMasterEn
						{
							ID = Utility.GetTableId(ConstValues.TableName.SysUserMasterEn),
							FullName = !string.IsNullOrEmpty(model.FullNameEN) ? model.FullNameEN?.Trim() :
								Utility.SetFullName(model.FamilyNameEN?.Trim(), model.FirstNameEN?.Trim(), ConstValues.Language.En),
							FamilyName = model.FamilyNameEN?.Trim(),
							FirstName = model.FirstNameEN?.Trim(),
							Call = model.CallEN,
							Address = model.AddressEN?.Trim(),
							Affiliation = model.AffiliationEN?.Trim(),
							Department = model.DepartmentEN?.Trim(),
							CV = model.CVEN?.Trim(),

							UserName = result.UserName,
							Mail = result.Mail,
							Gender = result.Gender,
							Degree = result.Degree,
							Country = result.Country,
							StateStr = result.StateStr,
							CityStr = result.CityStr,
							Telephone = result.Telephone,
							Mobile = result.Mobile,
							Career = career,
							OcisCode = ocisCode,
							HasUpdate = true,
							Status = ConstValues.Status.正常,
							Sort = ConstValues.DefaultSort,
							Creator = LoginUser.UserName,
							CreateIP = LoginUser.IP,
							CreateDate = DateTime.Now,
						};
						DbContext.SysUserMasterEn.Add(sysUserMasterEn);
					}
					else
					{
						sysUserMasterEn.FullName = !string.IsNullOrEmpty(model.FullNameEN) ? model.FullNameEN?.Trim() :
									Utility.SetFullName(model.FamilyNameEN?.Trim(), model.FirstNameEN?.Trim(), ConstValues.Language.En);
						sysUserMasterEn.FamilyName = model.FamilyNameEN?.Trim();
						sysUserMasterEn.FirstName = model.FirstNameEN?.Trim();
						sysUserMasterEn.Call = model.CallEN;
						sysUserMasterEn.Address = model.AddressEN?.Trim();
						sysUserMasterEn.Affiliation = model.AffiliationEN?.Trim();
						sysUserMasterEn.Department = model.DepartmentEN?.Trim();
						sysUserMasterEn.CV = model.CVEN?.Trim();

						sysUserMasterEn.Gender = result.Gender;
						sysUserMasterEn.Degree = result.Degree;
						sysUserMasterEn.Country = result.Country;
						sysUserMasterEn.Telephone = result.Telephone;
						sysUserMasterEn.Mobile = result.Mobile;
						sysUserMasterEn.Career = career;
						sysUserMasterEn.OcisCode = ocisCode;

						sysUserMasterEn.HasUpdate = true;
						sysUserMasterEn.Updater = LoginUser.UserName;
						sysUserMasterEn.UpdateDate = DateTime.Now;
						sysUserMasterEn.UpdateIP = LoginUser.IP;
					}
				}

				Utility.SaveInvoiceInfo(LoginUser, new InvoiceModel
				{
					InvoiceTitle = model.InvoiceTitle,
					TaxNum = model.TaxNum,
					AddressAndTel = model.AddressAndTel,
					Bank = model.Bank,
					BankAccount = model.BankAccount,
				});

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
				JsonRequestBehavior.AllowGet);			
		}

		public async Task<JsonCamelCaseResult> GetRoleData(SysUserMasterModel model)
		{
			var sql = from user in DbContext.SysUserAndRoleRelation.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 && x.UserId == model.UserId)
				  join actInfo in DbContext.SysRoleAndActionRelation.AsNoTracking()
					  .Where(x => x.Status == ConstValues.Status.正常)
				  on user.RoleId equals actInfo.RoleId into userInfos
				  from userInfo in userInfos.DefaultIfEmpty()
				  orderby user.Sort ascending, user.UpdateDate descending
				  select new
				  {
					  ID = user.ID,
					  UserId = user.UserId,
					  RoleId = user.RoleId,
					  ActionId = userInfo.ActionId,
				  };

			var sqlResult = await sql.ToListAsync();
			var result = sqlResult.Select(x => new
			{
				ID = x.ID,
				RoleName = DbContext.SysRoleMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.RoleId)?.RoleName,
				UserName = DbContext.SysUserMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.UserId)?.UserName,
				ActionName = DbContext.SysActionMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.ActionId)?.ActionName,
			})
			.OrderBy(x => x.RoleName).ToList();

			return JsonCamelCase(new
			{
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetRole(SysUserMasterModel model)
		{
			var result = await DbContext.SysRoleMaster.AsNoTracking()
				.Where(x => x.Status == ConstValues.Status.正常)
				.OrderBy(x => x.Sort)
				.ThenBy(x => x.RoleName)
				.Select(x => new
				{
					Id = x.ID,
					ActionName = x.RoleName
				})
				.ToListAsync();

			return JsonCamelCase(result, JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonResult> CreateRole(SysUserMasterModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			var result = await DbContext.SysUserAndRoleRelation
				.FirstOrDefaultAsync(x => x.UserId == model.UserId &&
				    x.RoleId == model.RoleId);
			if (result != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
					string.Format(Resources.MsgRecordExist, Resources.Name)),
					JsonRequestBehavior.AllowGet);
			}

			var SysRoleAndActionRelation = new SysUserAndRoleRelation
			{
				ID = Utility.GetTableId(ConstValues.TableName.SysUserAndRoleRelation),
				RoleId = model.RoleId,
				UserId = model.UserId,
				Status = ConstValues.Status.正常,
				Sort = ConstValues.DefaultSort,
				Remark = string.Empty,
				Creator = LoginUser.UserName,
				CreateIP = LoginUser.IP,
				CreateDate = DateTime.Now
			};

			DbContext.SysUserAndRoleRelation.Add(SysRoleAndActionRelation);
			await DbContext.SaveChangesAsync();

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
				JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> DeleteRole(SysUserMasterModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);
			var result = await DbContext.SysUserAndRoleRelation.FirstOrDefaultAsync(x => x.ID == model.HidRoleId);

			if (result != null)
			{
				DbContext.SysUserAndRoleRelation.Remove(result);
				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
					JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
					JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonCamelCaseResult> GetGroupData(SysUserMasterModel model)
		{
			var sql = from user in DbContext.SysUserAndGroupRelation.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 && x.UserId == model.UserIdGro)
				  join rolInfo in DbContext.SysGroupAndRoleRelation.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常)
				on user.UserGroupId equals rolInfo.UserGroupId into rolInfos
				  from rolInfo in rolInfos.DefaultIfEmpty()
				  join actInfo in DbContext.SysRoleAndActionRelation.AsNoTracking()
					  .Where(x => x.Status == ConstValues.Status.正常)
				  on rolInfo.RoleId equals actInfo.RoleId into actInfos
				  from actInfo in actInfos.DefaultIfEmpty()
				  orderby user.Sort ascending, user.UpdateDate descending
				  select new
				  {
					  ID = user.ID,
					  UserId = user.UserId,
					  RoleId = rolInfo.RoleId,
					  ActionId = actInfo.ActionId,
					  UserGroupId = user.UserGroupId
				  };

			var sqlResult = await sql.ToListAsync();
			var result = sqlResult.Select(x => new
			{
				ID = x.ID,
				GroupName = DbContext.SysUserGroupMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.UserGroupId)?.UserGroupName,
				UserName = DbContext.SysUserMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.UserId)?.UserName,
				RoleName = DbContext.SysRoleMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.RoleId)?.RoleName,
				ActionName = DbContext.SysActionMaster.AsNoTracking().FirstOrDefault(y => y.ID == x.ActionId)?.ActionName,
			})
			.OrderBy(x => x.GroupName).ToList();

			return JsonCamelCase(new
			{
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetGroup(SysUserMasterModel model)
		{
			var result = await DbContext.SysUserGroupMaster.AsNoTracking()
				.Where(x => x.Status == ConstValues.Status.正常)
				.OrderBy(x => x.Sort)
				.ThenBy(x => x.UserGroupName)
				.Select(x => new
				{
					Id = x.ID,
					ActionName = x.UserGroupName
				})
				.ToListAsync();

			return JsonCamelCase(result, JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonResult> CreateGroup(SysUserMasterModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			var result = await DbContext.SysUserAndGroupRelation
				.FirstOrDefaultAsync(x => x.UserId == model.UserIdGro &&
				    x.UserGroupId == model.GroupId);
			if (result != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
					string.Format(Resources.MsgRecordExist, Resources.Name)),
					JsonRequestBehavior.AllowGet);
			}

			var SysRoleAndActionRelation = new SysUserAndGroupRelation
			{
				ID = Utility.GetTableId(ConstValues.TableName.SysUserAndGroupRelation),
				UserGroupId = model.GroupId,
				UserId = model.UserIdGro,
				Status = ConstValues.Status.正常,
				Sort = ConstValues.DefaultSort,
				Remark = string.Empty,
				Creator = LoginUser.UserName,
				CreateIP = LoginUser.IP,
				CreateDate = DateTime.Now
			};

			DbContext.SysUserAndGroupRelation.Add(SysRoleAndActionRelation);
			await DbContext.SaveChangesAsync();

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
				JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> DeleteGroup(SysUserMasterModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			var result = await DbContext.SysUserAndGroupRelation.FirstOrDefaultAsync(x => x.ID == model.HidGroupId);

			if (result != null)
			{
				DbContext.SysUserAndGroupRelation.Remove(result);
				await DbContext.SaveChangesAsync();

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
					JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
					JsonRequestBehavior.AllowGet);
			}
		}

		public ActionResult DownloadImportTemplate()
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			return File(Resources.import_userInfo,
					"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
					$"import_userInfo.xlsx");
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> Import(SysUserMasterModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			if (model.ImportFile != null && model.ImportFile.InputStream.Length > 0)
			{
				try
				{
					var result = await this.ImportData(model.ImportFile.InputStream);

					if (!string.IsNullOrEmpty(_importMessage))
					{
						return JsonCamelCase(Utility.CreateFailJsonResult(_importMessage),
								JsonRequestBehavior.AllowGet, true);
					}
					else
					{
						return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessImport),
								JsonRequestBehavior.AllowGet, true);
					}
				}
				catch (Exception)
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgFileError),
							JsonRequestBehavior.AllowGet, true);
				}
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgInvalidFile),
					JsonRequestBehavior.AllowGet, true);
			}
		}

		private async Task<int> ImportData(Stream stream)
		{
			XSSFWorkbook workbook;
			workbook = new XSSFWorkbook(stream);

			ISheet sheet = workbook.GetSheetAt(0);
			int rowIndex = 0;
			int recordCount = 0;

			while (true)
			{
				var tmpMsg = string.Empty;
				try
				{
					rowIndex++;
					IRow row = sheet.GetRow(rowIndex);
					if (row == null)
					{
						break;
					}

					var model = new SysUserMasterModel();
					int columnIndex = 0;

					// 用户名
					if (row.GetCell(columnIndex) != null)
					{
						model.UserName = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.UserName))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.UserName, Resources.UserName) + "<br/>";
						}
						else if (model.UserName.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.UserName, Resources.UserName, 100) + "<br/>";
						}

						var exist = await DbContext.SysUserMaster.AsNoTracking().AnyAsync(x => x.UserName == model.UserName);
						if (exist)
						{
							tmpMsg += string.Format(Resources.MsgImportIsExist, model.UserName, Resources.UserName) + "<br/>";
						}
					}

					// 邮箱
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Mail = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.Mail))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.UserName, Resources.Mail) + "<br/>";
						}
						else if (model.Mail.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.UserName, Resources.Mail, 100) + "<br/>";
						}

						var exist = await DbContext.SysUserMaster.AsNoTracking().AnyAsync(x => x.UserName == model.Mail);
						if (exist)
						{
							tmpMsg += string.Format(Resources.MsgImportIsExist, model.UserName, Resources.Mail) + "<br/>";
						}
					}

					// 姓
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.FamilyName = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.FamilyName.Length > 50)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.UserName, Resources.FamilyName, 50) + "<br/>";
						}
					}

					// 名
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.FirstName = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.FirstName.Length > 50)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.UserName, Resources.FirstName, 50) + "<br/>";
						}
					}

					if (!string.IsNullOrEmpty(tmpMsg))
					{
						_importMessage += tmpMsg;
						continue;
					}

					var sysUserMaster = new SysUserMaster
					{
						ID = Utility.GetTableId(ConstValues.TableName.SysUserMaster),
						UserName = model.UserName?.Trim(),
						Mail = model.Mail?.Trim(),
						FamilyName = model.FamilyName?.Trim(),
						FirstName = model.FirstName?.Trim(),
						FullName = Utility.SetFullName(model.FamilyName?.Trim(), model.FirstName?.Trim(), ConstValues.Language.Cn),
						Language = ConstValues.Language.Cn,
						Gender = true,
						Affiliation = ConstValues.DefaultEmpty,
						Call = 7,
						Degree = 4,
						Country = 7,
						Career = "12",
						OcisCode = "44",
						Password = StringExtension.Encrypt(ConstValues.DefaultPassword),
						IsLocked = false,
						PasswordFailed = ConstValues.intZero,
						Status = ConstValues.Status.正常,
						Sort = ConstValues.DefaultSort,
						Creator = LoginUser.UserName,
						CreateIP = LoginUser.IP,
						CreateDate = DateTime.Now,
						HasSend = false
					};
					DbContext.SysUserMaster.Add(sysUserMaster);

					await DbContext.SaveChangesAsync();

					recordCount++;
				}
				catch (Exception)
				{
					continue;
				}
			}

			return await Task.FromResult(recordCount);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<FileResult> Export(string allId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName);

			var ids = allId.Split(ConstValues.chrComma);
			var sql = from userInfo in DbContext.SysUserMaster.AsNoTracking().Where(x => !string.IsNullOrEmpty(x.Status) && ids.Contains(x.ID.ToString()))
				  join userEn in DbContext.SysUserMasterEn.AsNoTracking()
					on userInfo.UserName equals userEn.UserName into userInfoEns
				  from userInfoEn in userInfoEns.DefaultIfEmpty()
				  orderby userInfo.Sort ascending, userInfo.CreateDate descending
				  select new
				  {
					  ID = userInfo.ID,
					  UserName = userInfo.UserName,
					  Mail = userInfo.Mail,
					  Language = userInfo.Language,
					  FullName = userInfo.FullName,
					  FamilyName = userInfo.FamilyName,
					  FirstName = userInfo.FirstName,
					  FullNameEn = userInfoEn.FullName,
					  FamilyNameEn = userInfoEn.FamilyName,
					  FirstNameEn = userInfoEn.FirstName,
					  Gender = userInfo.Gender,
					  Birthday = userInfo.Birthday,
					  Call = userInfo.Call,
					  CallEn = userInfoEn.Call,
					  Degree = userInfo.Degree,
					  Career = userInfo.Career,
					  OcisCode = userInfo.OcisCode,
					  CV = userInfo.CV,
					  CVEn = userInfoEn.CV,
					  Affiliation = userInfo.Affiliation,
					  Department = userInfo.Department,
					  AffiliationEn = userInfoEn.Affiliation,
					  DepartmentEn = userInfoEn.Department,
					  Address = userInfo.Address,
					  AddressEn = userInfoEn.Address,
					  ZipCode = userInfo.ZipCode,
					  Country = userInfo.Country,
					  State = userInfo.StateStr,
					  City = userInfo.CityStr,
					  Mobile = userInfo.Mobile,
					  Telephone = userInfo.Telephone,
					  InvoiceTitle = userInfo.InvoiceTitle,
					  TaxNum = userInfo.TaxNum,
					  AddressAndTel = userInfo.AddressAndTel,
					  Bank = userInfo.Bank,
					  BankAccount = userInfo.BankAccount,
					  Status = userInfo.Status,
					  IsLocked = userInfo.IsLocked,
					  Remark = userInfo.Remark,
					  Creator = userInfo.Creator,
					  CreateIP = userInfo.CreateIP,
					  CreateDate = userInfo.CreateDate
				  };

			var result = await sql.ToListAsync();

			var callMaster = await DbContext.CallMaster.AsNoTracking()
					.ToListAsync();

			var degreeMaster = await DbContext.DegreeMaster.AsNoTracking()
					.ToListAsync();

			var locationMaster = await DbContext.LocationMaster.AsNoTracking()
					.Where(x => x.Level == ConstValues.LocationLevel.国家)
					.ToListAsync();

			var export = Resources.export_userInfo;

			XSSFWorkbook workbook;

			using (MemoryStream readStream = new MemoryStream(export))
			{
				workbook = new XSSFWorkbook(readStream);
				ISheet sheet = workbook.GetSheetAt(0);

				var count = 0;
				foreach (var model in result)
				{
					count += 1;
					IRow row = sheet.CreateRow(count);

					// 用户名
					int column = 0;
					ICell cell = row.CreateCell(column);
					cell.SetCellValue(model.UserName);

					// 邮箱
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Mail);

					// 默认语言
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Language);

					// 姓名
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.FullName);

					// 姓
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.FamilyName);

					// 名
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.FirstName);

					// 姓名（EN）
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.FullNameEn);

					// 姓（EN）
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.FamilyNameEn);

					// 名（EN）
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.FirstNameEn);

					// 性别
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Gender ? ConstValues.Gender.男 : ConstValues.Gender.女);

					// 生日
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Birthday?.ToString("yyyy-MM-dd"));

					// 称呼
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(callMaster.FirstOrDefault(x => x.ID == model.Call)?.CallName);

					// 称呼（EN）
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(callMaster.FirstOrDefault(x => x.ID == model.CallEn)?.CallNameEn);

					// 最高学历
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(LoginUser.Language == ConstValues.Language.Cn ?
							degreeMaster.FirstOrDefault(x => x.ID == model.Degree)?.DegreeName :
							degreeMaster.FirstOrDefault(x => x.ID == model.Degree)?.DegreeNameEn);

					// 职业
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(Utility.GetNameFromIdList(model.Career, "career", LoginUser.Language));

					// 研究领域
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(Utility.GetNameFromIdList(model.OcisCode, "ocis"));

					// 个人简介
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.CV);

					// 个人简介（EN）
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.CVEn);

					// 单位
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Affiliation);

					// 单位（EN）
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.AffiliationEn);

					// 部门
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Department);

					// 部门（EN）
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.DepartmentEn);

					// 地址
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Address);

					// 地址（EN）
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.AddressEn);

					// 邮编
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.ZipCode);

					// 国家
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(LoginUser.Language == ConstValues.Language.Cn ?
							locationMaster.FirstOrDefault(x => x.ID == model.Country)?.Name :
							locationMaster.FirstOrDefault(x => x.ID == model.Country)?.NameEn);

					// 省/市
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.State);

					// 城市/区
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.City);

					// 手机
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Mobile);

					// 固定电话
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Telephone);

					// 发票抬头
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.InvoiceTitle);

					// 纳税人识别号
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.TaxNum);

					// 地址、电话
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.AddressAndTel);

					// 开户行
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Bank);

					// 开户行账号
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.BankAccount);

					// 状态
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Status);

					// 锁定
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.IsLocked ? Resources.Yes : Resources.No);

					// 备注
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Remark);

					// 创建者
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.Creator);

					// 创建IP
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.CreateIP);

					// 创建日期
					column++;
					cell = row.CreateCell(column);
					cell.SetCellValue(model.CreateDate.Value.ToString("yyyy-MM-dd"));
				}
			}

			MemoryStream exportStream = new MemoryStream();
			workbook.Write(exportStream);
			exportStream.Flush();
			exportStream.Position = 0;

			return File(exportStream, Application.Octet,
					$"export_userInfo_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
		}
	}
}